package com.shop.front.dao.user;

import com.shop.jpa.BaseDao;
import com.shop.domain.user.UserPinkBill;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Repository
public interface UserPinkBillDao extends BaseDao<UserPinkBill, Long> {


    @Query("from UserPinkBill where uid = ?2 and linkId = ?1 order by createTime desc")
    List<UserPinkBill> findAllByLinkIdAndUid(Long storePinkId,Long userId);

    @Query(nativeQuery = true, value = "select ifnull(sum(price), 0) from t_user_pink_bill where uid = ?1 and pm = 0 and table_name =?3 and create_time >= ?2 and create_time < date_add(?2, interval 1 day)")
    public BigDecimal sumByDate(Long userId, Date date,String type);

    @Query(nativeQuery = true, value = "select ifnull(sum(price), 0) from t_user_pink_bill where uid = ?1 and pm = 0  and create_time >= date_sub(?2, interval 1 day) and create_time < ?2")
    public BigDecimal sumByBeforeDate(Long userId, Date date);
}
